package yazan.com.pdacollector_android.model;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "GOODS".
*/
public class GoodsDao extends AbstractDao<Goods, Long> {

    public static final String TABLENAME = "GOODS";

    /**
     * Properties of entity Goods.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property Id = new Property(0, long.class, "id", true, "_id");
        public final static Property Forder_id = new Property(1, long.class, "Forder_id", false, "FORDER_ID");
        public final static Property FIndex = new Property(2, int.class, "FIndex", false, "FINDEX");
        public final static Property Forder_sn = new Property(3, String.class, "Forder_sn", false, "FORDER_SN");
        public final static Property Fgoods_name = new Property(4, String.class, "Fgoods_name", false, "FGOODS_NAME");
        public final static Property Fgoods_spec = new Property(5, String.class, "Fgoods_spec", false, "FGOODS_SPEC");
        public final static Property Fgoods_sn = new Property(6, String.class, "Fgoods_sn", false, "FGOODS_SN");
        public final static Property Fgoods_qty = new Property(7, int.class, "Fgoods_qty", false, "FGOODS_QTY");
        public final static Property Validation_type = new Property(8, int.class, "validation_type", false, "VALIDATION_TYPE");
        public final static Property Validation_count = new Property(9, int.class, "validation_count", false, "VALIDATION_COUNT");
        public final static Property Page_index = new Property(10, int.class, "page_index", false, "PAGE_INDEX");
        public final static Property FOrderDate = new Property(11, java.util.Date.class, "FOrderDate", false, "FORDER_DATE");
        public final static Property Fiscode = new Property(12, int.class, "Fiscode", false, "FISCODE");
        public final static Property Fgoods_codes = new Property(13, String.class, "Fgoods_codes", false, "FGOODS_CODES");
    }

    private Query<Goods> orderInfo_DataQuery;

    public GoodsDao(DaoConfig config) {
        super(config);
    }
    
    public GoodsDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"GOODS\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ," + // 0: id
                "\"FORDER_ID\" INTEGER NOT NULL ," + // 1: Forder_id
                "\"FINDEX\" INTEGER NOT NULL ," + // 2: FIndex
                "\"FORDER_SN\" TEXT," + // 3: Forder_sn
                "\"FGOODS_NAME\" TEXT," + // 4: Fgoods_name
                "\"FGOODS_SPEC\" TEXT," + // 5: Fgoods_spec
                "\"FGOODS_SN\" TEXT," + // 6: Fgoods_sn
                "\"FGOODS_QTY\" INTEGER NOT NULL ," + // 7: Fgoods_qty
                "\"VALIDATION_TYPE\" INTEGER NOT NULL ," + // 8: validation_type
                "\"VALIDATION_COUNT\" INTEGER NOT NULL ," + // 9: validation_count
                "\"PAGE_INDEX\" INTEGER NOT NULL ," + // 10: page_index
                "\"FORDER_DATE\" INTEGER," + // 11: FOrderDate
                "\"FISCODE\" INTEGER NOT NULL ," + // 12: Fiscode
                "\"FGOODS_CODES\" TEXT);"); // 13: Fgoods_codes
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"GOODS\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, Goods entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
        stmt.bindLong(2, entity.getForder_id());
        stmt.bindLong(3, entity.getFIndex());
 
        String Forder_sn = entity.getForder_sn();
        if (Forder_sn != null) {
            stmt.bindString(4, Forder_sn);
        }
 
        String Fgoods_name = entity.getFgoods_name();
        if (Fgoods_name != null) {
            stmt.bindString(5, Fgoods_name);
        }
 
        String Fgoods_spec = entity.getFgoods_spec();
        if (Fgoods_spec != null) {
            stmt.bindString(6, Fgoods_spec);
        }
 
        String Fgoods_sn = entity.getFgoods_sn();
        if (Fgoods_sn != null) {
            stmt.bindString(7, Fgoods_sn);
        }
        stmt.bindLong(8, entity.getFgoods_qty());
        stmt.bindLong(9, entity.getValidation_type());
        stmt.bindLong(10, entity.getValidation_count());
        stmt.bindLong(11, entity.getPage_index());
 
        java.util.Date FOrderDate = entity.getFOrderDate();
        if (FOrderDate != null) {
            stmt.bindLong(12, FOrderDate.getTime());
        }
        stmt.bindLong(13, entity.getFiscode());
 
        String Fgoods_codes = entity.getFgoods_codes();
        if (Fgoods_codes != null) {
            stmt.bindString(14, Fgoods_codes);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, Goods entity) {
        stmt.clearBindings();
        stmt.bindLong(1, entity.getId());
        stmt.bindLong(2, entity.getForder_id());
        stmt.bindLong(3, entity.getFIndex());
 
        String Forder_sn = entity.getForder_sn();
        if (Forder_sn != null) {
            stmt.bindString(4, Forder_sn);
        }
 
        String Fgoods_name = entity.getFgoods_name();
        if (Fgoods_name != null) {
            stmt.bindString(5, Fgoods_name);
        }
 
        String Fgoods_spec = entity.getFgoods_spec();
        if (Fgoods_spec != null) {
            stmt.bindString(6, Fgoods_spec);
        }
 
        String Fgoods_sn = entity.getFgoods_sn();
        if (Fgoods_sn != null) {
            stmt.bindString(7, Fgoods_sn);
        }
        stmt.bindLong(8, entity.getFgoods_qty());
        stmt.bindLong(9, entity.getValidation_type());
        stmt.bindLong(10, entity.getValidation_count());
        stmt.bindLong(11, entity.getPage_index());
 
        java.util.Date FOrderDate = entity.getFOrderDate();
        if (FOrderDate != null) {
            stmt.bindLong(12, FOrderDate.getTime());
        }
        stmt.bindLong(13, entity.getFiscode());
 
        String Fgoods_codes = entity.getFgoods_codes();
        if (Fgoods_codes != null) {
            stmt.bindString(14, Fgoods_codes);
        }
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.getLong(offset + 0);
    }    

    @Override
    public Goods readEntity(Cursor cursor, int offset) {
        Goods entity = new Goods( //
            cursor.getLong(offset + 0), // id
            cursor.getLong(offset + 1), // Forder_id
            cursor.getInt(offset + 2), // FIndex
            cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3), // Forder_sn
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // Fgoods_name
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // Fgoods_spec
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // Fgoods_sn
            cursor.getInt(offset + 7), // Fgoods_qty
            cursor.getInt(offset + 8), // validation_type
            cursor.getInt(offset + 9), // validation_count
            cursor.getInt(offset + 10), // page_index
            cursor.isNull(offset + 11) ? null : new java.util.Date(cursor.getLong(offset + 11)), // FOrderDate
            cursor.getInt(offset + 12), // Fiscode
            cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13) // Fgoods_codes
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, Goods entity, int offset) {
        entity.setId(cursor.getLong(offset + 0));
        entity.setForder_id(cursor.getLong(offset + 1));
        entity.setFIndex(cursor.getInt(offset + 2));
        entity.setForder_sn(cursor.isNull(offset + 3) ? null : cursor.getString(offset + 3));
        entity.setFgoods_name(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setFgoods_spec(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setFgoods_sn(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setFgoods_qty(cursor.getInt(offset + 7));
        entity.setValidation_type(cursor.getInt(offset + 8));
        entity.setValidation_count(cursor.getInt(offset + 9));
        entity.setPage_index(cursor.getInt(offset + 10));
        entity.setFOrderDate(cursor.isNull(offset + 11) ? null : new java.util.Date(cursor.getLong(offset + 11)));
        entity.setFiscode(cursor.getInt(offset + 12));
        entity.setFgoods_codes(cursor.isNull(offset + 13) ? null : cursor.getString(offset + 13));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(Goods entity, long rowId) {
        entity.setId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(Goods entity) {
        if(entity != null) {
            return entity.getId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(Goods entity) {
        throw new UnsupportedOperationException("Unsupported for entities with a non-null key");
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "Data" to-many relationship of OrderInfo. */
    public List<Goods> _queryOrderInfo_Data(long Forder_id) {
        synchronized (this) {
            if (orderInfo_DataQuery == null) {
                QueryBuilder<Goods> queryBuilder = queryBuilder();
                queryBuilder.where(Properties.Forder_id.eq(null));
                orderInfo_DataQuery = queryBuilder.build();
            }
        }
        Query<Goods> query = orderInfo_DataQuery.forCurrentThread();
        query.setParameter(0, Forder_id);
        return query.list();
    }

}
